package setup;


import java.util.Scanner;
import java.util.Hashtable;
import java.util.InputMismatchException;;

public class dealer {
	
	/**
	 * Directly Deals the cards to each player, base level for running game.
	 */
	
	static Hashtable cards = new Hashtable();
	static Scanner scan = new Scanner(System.in);
	
	public static void main(String[] args) {
		/**
		 * The main class runs the program and main logic interface to deal cards, and create a viable game.
		 */
		
		//References the card values with the card names - for future reference.
		cards.put(20,"Joker"); cards.put(19, "HighBower"); cards.put(18, "LowBower"); cards.put(17, "Ace"); 
		cards.put(16, "King"); cards.put(15, "Queen"); cards.put(14, "Jack"); cards.put(13, "13"); cards.put(12, "12");
		cards.put(11, "11"); cards.put(10, "10"); cards.put(9, "9"); cards.put(8, "8"); cards.put(7, "7");
		cards.put(6, "6"); cards.put(5, "5"); cards.put(4, "4"); cards.put(3, "3"); cards.put(2, "2");
		
		int playOption = 2; //TODO: Needs to change to 0, to be outside of normal range when testing.
		int players = 4; //TODO: Needs to change to 0, to be outside of normal range when testing.
		
		//If Options aren't preset, prompts the reader for preference.
		askGameOption(playOption);
		askPlayers(players);
		
		if (playOption == 1) {
			playAI(players, playOption);
		} else if (playOption == 2) {
			playLocal(players, playOption);
		}
		
	}
	
	private static void playAI(int players, int playOption) {
		Object[] hands = dealHands(players);
		
		//TODO: Create Hand Instance.
	}
	
	private static void playLocal(int players, int playOption) {
		Object[] hands = dealHands(players);
	}
	
	private static Object[] dealHands(int hands) {
		
		String[][] cardLists = new String[hands][10];
		
		//Shows what cards are used in with different players amounts.
		final String[] suites = new String[] {"H","D","C","S"}; //Hearts, Diamonds, Clubs, Spades.
		final int[] deck3P = new int[] {20,17,16,15,14,10,9,8,7};
		final int[] deck4P = new int[] {20,17,16,15,14,10,9,8,7,6,5,4};
		final int[] deck5P = new int[] {20,17,16,15,14,10,9,8,7,6,5,4,3,2};
		final int[] deck6P = new int[] {20,17,16,15,14,13,12,11,10,9,8,7,6,5,4,3,2};
		final int[][] decks = new int[][] {deck3P,deck4P,deck5P,deck6P};

		//TODO: Allocate each card with a suite (Need to be careful for trump cards) to a random hand.
		// OR allocate a random card to a iterated hand slot.
		if (hands == 3) {
			
		} else if (hands == 4) {
			
		} else if (hands == 5) {
			
		} else {
			
		}

		Object[] cardHands = new Object[hands];
		
		//TODO: Create Hand Instance for each Hand - Return as cardHands.
		for (int i = 0; i < hands; i++) {
			cardHands[i] = new hand(cardLists[i]); 
		}
		
		return cardHands;
	}
	
	private static void askPlayers(int players) {
		/*Asks the user how many player they want in their game.*/
		
		System.out.print("How many players would you like in the game? (3 to 6)\n>");
		while (players < 3 || players > 6) {
			try {
				players = scan.nextInt();
			} catch (InputMismatchException error) {
				scan.nextLine();
				System.out.print("The input was entered wrong. You should specify an option as a single integer.\n" +
						"Please try again:\n>");
			}			
		} 
	}

	private static void askGameOption(int playOption) {

		System.out.print("Welcome to the 500 card game. Please select an option:\n" +
				"1. Play versus AI.\n" +
				"2. Play Versus With Yourself\n>");
		while (playOption != 1 || playOption != 2) {
			try {
				playOption = scan.nextInt();
			} catch (InputMismatchException error) {
				scan.nextLine();
				System.out.print("The input was entered wrong. You should specify an option as a single integer.\n" +
						"Please try again:\n>");
			}
		}
	}
}
